package io;

import java.io.*;

/*
  使用缓冲流完成文件的复制操作
  缓冲流是一对高级流，功能:提高读写效率
  JAVA IO将流分为两类: 节点流和处理流（过滤流）
 */
public class CopyDemo3 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("image_dog.jpg");
        BufferedInputStream bis = new BufferedInputStream(fis);
        FileOutputStream fos = new FileOutputStream("image_dog1.jpg");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        /*
          缓冲流默认的构造器
          BufferedInputStream(InputStream in)
          内部开辟了字节数组长度为8kb

          BufferedInputStream()
         */
        int d;
        long start = System.currentTimeMillis();
        while((d = bis.read())!=-1){
            bos.write(d);
        }
        long end = System.currentTimeMillis();
        System.out.println("读写完成,耗时:"+(end-start)+"ms");
        bis.close();
        bos.close();
    }
}
